package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.config.Config;
import com.example.a14110100409.yuejiandemo.javabean.ShaiTuComment;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;


public class ShaiTuCommentAdapter extends RecyclerView.Adapter {

    private List<ShaiTuComment> shaiTuComments;
    private Context context;
    private LayoutInflater layoutInflater;

    public ShaiTuCommentAdapter(Context context,List<ShaiTuComment> shaiTuComments){
        this.context=context;//保存上下文
        this.shaiTuComments=shaiTuComments;//显示内容
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView=LayoutInflater.from(context).inflate(R.layout.item_shaitu_comment,viewGroup,false);
        ShaiTuCommentViewHolder holder=new ShaiTuCommentViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        ShaiTuCommentViewHolder shaiTuCommentViewHolder= (ShaiTuCommentViewHolder) viewHolder;
        ShaiTuComment shaiTuComment=shaiTuComments.get(position);
        String c_name=shaiTuComment.getUser_name();
        String c_time=shaiTuComment.getReply_time();
        String c_content=shaiTuComment.getReply();
        String c_pic=shaiTuComment.getPhoto();
        if (c_name==null){
            shaiTuCommentViewHolder.comment_name.setText("薛烜");
        }else{
        shaiTuCommentViewHolder.comment_name.setText(c_name);
        }
        shaiTuCommentViewHolder.comment_time.setText(c_time);
        shaiTuCommentViewHolder.comment_content.setText(c_content);
        if(c_pic==null){
            Picasso.with(context).load(R.drawable.dog_1).into(shaiTuCommentViewHolder.comment_pic);
        }else{
        Picasso.with(context).load(Config.PIC_URL+c_pic).into(shaiTuCommentViewHolder.comment_pic);
        }
    }

    @Override
    public int getItemCount() {
        return shaiTuComments.size();
    }

    public class ShaiTuCommentViewHolder extends RecyclerView.ViewHolder{

        public ImageView comment_pic;
        public TextView comment_name;
        public TextView comment_time;
        public TextView comment_content;
        public View itemView;

        public ShaiTuCommentViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            comment_pic= (ImageView) itemView.findViewById(R.id.shaitu_comment_pic);
            comment_name= (TextView) itemView.findViewById(R.id.shaitu_comment_name);
            comment_time= (TextView) itemView.findViewById(R.id.shaitu_comment_time);
            comment_content= (TextView) itemView.findViewById(R.id.shaitu_comment_content);
        }
    }
}
